// ActionScript file
package chamans.webphp
{
	import flash.display.*;
	import flash.events.*;
	import flash.geom.*;
		
public class Scroll extends MovieClip{

private var barre:MovieClip;
private var scrol:MovieClip;
private var ratio:Number;
private var Cible:MovieClip;
public var actif:Boolean=false;
private var maxi:int;
private var decal:int;
public function Scroll():void {
	barre = new MovieClip;
	scrol = new MovieClip;

	
	
}

public function init(Tx:int, x:int, y:int, Ty:int, cible:*, tailltotal:int):void{
	this.x=x; this.y=y;
	Cible=cible;
//	barre.height=Ty;  barre.width=Tx;
	var f:Shape=carre(0x333333,.5, Tx, Ty);
	barre.addChild(f);
	addChild(barre);
	var g:Shape=carre(0xffff00, 1, Tx, 30);
	scrol.addChild(g);
	addChild(scrol);
	ratio = ((((tailltotal - Ty) / (Ty- scrol.height))*100))/100;
    actif=true;
		}
public function ActiveScroll():void{
	//scrol.mouseChildren=false;
	scrol.mouseEnabled=true;
	scrol.buttonMode=true;
    scrol.addEventListener ('mouseOver',SOver);
    scrol.addEventListener ('mouseDown',SPress);
    scrol.addEventListener ('mouseOut',SOut);
   // this.mouseEnabled=false;
		}
public function inActiveScroll():void{
scrol.removeEventListener ('mouseOver',SOver);
scrol.removeEventListener ('mouseDown',SPress);
scrol.removeEventListener ('mouseOut',SOut);
scrol.visible=barre.visible=false;
actif=false;
		}
private function SOver(e:MouseEvent):void {//scrol.gotoAndStop(2);//UpDown = true ;
}
private function SOut(e:MouseEvent):void { //scrol.gotoAndStop(1);//UpDown = false;
}
private function SPress(e:MouseEvent):void { 
              // if(UpDown){
				//scrol.gotoAndStop(3); barre.gotoAndStop(2);
              //  scrol.startDrag (false,new Rectangle( barre.x, barre.y, 0, barre.height-scrol.height));
				maxi=barre.height-scrol.height
				decal=scrol.mouseY;
				 this.addEventListener ('enterFrame',Cmove, false, 0, true);
				
				scrol.addEventListener ('mouseOut',SRelease);
                scrol.addEventListener ('mouseUp',SRelease);
			//	this.parent.addEventListener ('mouseUp',SRelease);
				//if(parent.parent.parent.m3d) parent.parent.parent.m3d.MoveOn=false;
				}
private function Cmove(e:Event):void {
	if(scrol.y>=0 && scrol.y<=maxi)scrol.y=mouseY-decal
	if(scrol.y<0)scrol.y=0
	if(scrol.y>maxi)scrol.y=maxi

	Cible.y = - uint(scrol.y*ratio);
}
private function SRelease(e:MouseEvent):void {
	                 this.removeEventListener ('enterFrame',Cmove);
	            //  UpDown = false;
               //  scrol.gotoAndStop(1);barre.gotoAndStop(1);  
                 scrol.stopDrag();
				 scrol.removeEventListener ('mouseOut',SRelease);
                 scrol.removeEventListener ('mouseUp',SRelease);
				// this.parent.removeEventListener ('mouseUp',SRelease);
}
//_____graph
private function carre(c:int=0x00, a:Number=1,  w:int=1, h:int=1, r:int=5 ):Shape { 	
	var g:Shape=new Shape()
	g.graphics.beginFill(c, a);
	g.graphics.drawRoundRect(0,0,w,h, r, r);
	g.graphics.endFill()
	return g  
}

}}